#include "ftgridmodel.h"

FtGridModel::FtGridModel()
{
    /* 建立信号和槽，启动定时器 */
    connect(&timer, &QTimer::timeout, this, &FtGridModel::onTimeout);
    timer.start(1000);
}

int FtGridModel::rowCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    return 6;
}

int FtGridModel::columnCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    return 1;
}

QVariant FtGridModel::data(const QModelIndex &index, int role) const
{
    Q_UNUSED(index);
    QVariant value;
    switch(role)
    {
    case RandValue:
        value = rand();
        break;
    }
    return value;
}

QHash<int, QByteArray> FtGridModel::roleNames() const
{
    QHash<int, QByteArray> roles;
    roles.insert(RandValue, "RandValue");
    return roles;
}

void FtGridModel::onTimeout()
{
    QModelIndex topLeft = createIndex(0, 0);
    QModelIndex bottomRight = createIndex(5, 0);
    emit dataChanged(topLeft, bottomRight);
}
